﻿
@page "/Wms/BuyInWarehouse/BatchEdit"
@using nERP.ViewModel.Wms.BuyInWarehouseVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
  <div style="margin-bottom:10px;"> @WtmBlazor.Localizer["Sys.BatchEditConfirm"]</div>
  <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.Normal">
    <Select @bind-Value="@Model.LinkedVM.BuyId" Items="AllBuys" Id="g3b53df01e8a94a22b2f14716671e3f5f"/>
    <Select @bind-Value="@Model.LinkedVM.SupplierId" Items="AllSuppliers" Id="gaf62354d2ec84f96b574bd6d454f3632"/>
    <DateTimePicker @bind-Value="@Model.LinkedVM.InvoicesDate"/>
    <Select @bind-Value="@Model.LinkedVM.Status" Id="g8c44eee1c1f1416da1cd4efc7cc54c69"/>
    <BootstrapInput @bind-Value="@Model.LinkedVM.Remark"/>
  </Row>

  <div class="modal-footer table-modal-footer">
    <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]"/>
    <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]"/>
  </div>

</ValidateForm>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private BuyInWarehouseBatchVM Model = new BuyInWarehouseBatchVM();
    private ValidateForm vform { get; set; }
    
    private async Task Submit(EditContext context)
    {
        Model.Ids = ids;
        await PostsForm(vform, "/api/Wms/BuyInWarehouse/BatchEdit", (s) => WtmBlazor.Localizer["Sys.BatchEditSuccess", s], method: HttpMethodEnum.POST);
    }
            

    public void OnClose()
    {
        CloseDialog();
    }
    
    private List<SelectedItem> AllBuys = new List<SelectedItem>();
    private List<SelectedItem> AllSuppliers = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {
        
        
        AllBuys = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyInWarehouse/GetBuys");
        AllBuys.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });
        AllSuppliers = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyInWarehouse/GetSuppliers");
        AllSuppliers.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });

        await base.OnInitializedAsync();
    }
}
